package com.digitalchina.lxnsy.activity.old;

import android.os.Bundle;
import androidx.recyclerview.widget.LinearLayoutManager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.digitalchina.lxnsy.R;
import com.digitalchina.lxnsy.base.BaseActivity;
import com.digitalchina.lxnsy.entity.AgriSpecialInfoVO;
import com.digitalchina.lxnsy.entity.CafProblemVO;
import com.digitalchina.lxnsy.toolkit.GotoUtil;
import com.digitalchina.lxnsy.viewholder.CafMainHolder;
import com.jude.easyrecyclerview.EasyRecyclerView;
import com.jude.easyrecyclerview.adapter.BaseViewHolder;
import com.jude.easyrecyclerview.adapter.RecyclerArrayAdapter;

import java.util.ArrayList;
import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * ================================================
 * 项目名称：BigData
 * 类描述：
 * 包名：com.digitalchina.bigdata.activity
 * 创建人：郑皓
 * 创建时间：2017/10/27 16:29
 * 修改备注：
 * ================================================
 */
public class CafListActivity extends BaseActivity {


    @Bind(R.id.recycler_view)
    EasyRecyclerView recyclerView;


    private View headView;//头布局
    private TextView tvTitle;
    private TextView tvContent;

    private RecyclerArrayAdapter adapter;
    private List<CafProblemVO> voList = new ArrayList<>();
    private AgriSpecialInfoVO agriSpecialInfo;


    @Override
    public void setLayout() {
        setContentLayout(R.layout.activity_caf_main);
        setTitle("农高会专题");
    }

    @Override
    public void initMember() {


        headView = LayoutInflater.from(this).inflate(R.layout.view_caf_list, null);
        tvTitle = (TextView) headView.findViewById(R.id.caf_list_tv_title);
        tvContent = (TextView) headView.findViewById(R.id.caf_list_tv_content);

        recyclerView.setLayoutManager(new LinearLayoutManager(this));
//        recyclerView.addItemDecoration(Utils.setDividerDecoration(this, 1, 0, 0));

        recyclerView.setAdapterWithProgress(adapter = new RecyclerArrayAdapter(this) {
            @Override
            public BaseViewHolder OnCreateViewHolder(ViewGroup parent, int viewType) {
                return new CafMainHolder(parent);
            }
        });


        adapter.addHeader(new RecyclerArrayAdapter.ItemView() {
            @Override
            public View onCreateView(ViewGroup parent) {

                return headView;
            }

            @Override
            public void onBindView(View headerView) {


            }
        });

        recyclerView.setAdapter(adapter);

        voList = (List<CafProblemVO>) getIntent().getSerializableExtra("list");
        for (int i = 0; i < voList.size(); i++) {
            if (voList.get(i).isSelect()) {
                tvTitle.setText(voList.get(i).getProblemTitle());
                tvContent.setText(voList.get(i).getProblemAnswer());
            }
        }
        adapter.clear();
        adapter.addAll(voList);


    }

    @Override
    public void addListener() {




        adapter.setOnItemClickListener(new RecyclerArrayAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(int position) {
                List<CafProblemVO> list = adapter.getAllData();
                for (int i = 0; i < list.size(); i++) {
                    list.get(i).setSelect(i == position);
                }
                GotoUtil.gotoActivity(CafListActivity.this, CafListActivity.class, true, "list", list);
            }
        });
    }

    @Override
    public void setHandler() {
    }

    @Override
    public void callBack(Object object) {
    }

    @Override
    public void rightOnClick() {

    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // TODO: add setContentView(...) invocation
        ButterKnife.bind(this);
    }

}
